package com.xiaoran.robot.controller;

import com.xiaoran.robot.entity.Dicts;
import com.xiaoran.robot.service.DictsService;
import com.xiaoran.robot.service.WsCosService;
import com.xiaoran.robot.task.PlmmTask;
import com.xiaoran.robot.utils.MiraiUtils;
import org.java_websocket.client.WebSocketClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
public class MainController {
    MiraiUtils miraiUtils = new MiraiUtils();
    @Autowired
    WebSocketClient webSocketClient;
    @Autowired
    WsCosService wsCosService;
    @Autowired
    DictsService dictsService;
    @GetMapping("/test")
    public void test(){
        PlmmTask plmmTask = new PlmmTask();
        plmmTask.task();
    }
    @GetMapping("/admin")
    public ModelAndView admin(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        List<Dicts> dicts = dictsService.selectList();
        modelAndView.addObject("dataDicts", dicts);
        return modelAndView;
    }

    /**
     * 新增关键词
     */
    @PostMapping("/addKeywords")
    public boolean addKeywords(Dicts data){
        return dictsService.insertOne(data) == 1;
    }
    /**
     * 更新词库文件
     */
    @GetMapping("/refreshDicts")
    public void refreshDicts(){
        dictsService.dictsToJson();
    }
    /**
     * 根据 id 获取词库
     */
    @GetMapping("/getDict")
    public Dicts getOne(Integer id){
        return dictsService.getOne(id);
    }
    /**
     * 根据 id 删除一条关键词
     */
    @PostMapping("/delDict")
    public void delDict(Integer id){
        dictsService.delDict(id);
    }
}
